package wang.ddcat.reptilian_plus.util;

import java.util.ArrayList;
import java.util.List;

public class JsonResult<T> {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 返回message
     */
    private String message;

    /**
     * 出现异常的URL
     */
    private String url;

    /**
     * 结果
     */
    private List<T> result = new ArrayList<T>();

    private Integer count = 0;

    public JsonResult() {
    }

    public JsonResult count(Integer count){
        this.count = count;
        return this;
    }
    /*
    public JsonResult(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    public JsonResult(Integer code,String message,List<T> result){
        this.code = code;
        this.message = message;
        this.result = result;
    }
    */

    public static JsonResult error(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(500);
        jsonResult.setMessage("error");
        return jsonResult;
    }

    public static JsonResult error(String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(500);
        jsonResult.setMessage(message);
        return jsonResult;
    }

    public static JsonResult error(Integer code, String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(code);
        jsonResult.setMessage(message);
        return jsonResult;
    }

    public static JsonResult success(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(200);
        jsonResult.setMessage("success");
        return jsonResult;
    }

    public JsonResult setResult(T t){
        if(t!=null){
            result.add(t);
            this.setResult(result);
        }
        return this;
    }


    public static JsonResult success(List result) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(200);
        jsonResult.setMessage("success");
        jsonResult.setResult(result);
        return jsonResult;
    }

    public static JsonResult url(String url) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(200);
        jsonResult.setMessage("success");
        jsonResult.setUrl(url);
        return jsonResult;
    }


    public static JsonResult success(Integer code, String message, List result){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(code);
        jsonResult.setMessage(message);
        jsonResult.setResult(result);
        return jsonResult;
    }

    public JsonResult message(String  message){
        this.message = message;
        return this;
    }

    public JsonResult code(Integer  code){
        this.code = code;
        return this;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }
}
